package cn.edu.scau.cmi.ema.dao;

import cn.edu.scau.cmi.ema.base.CmiPagination;
import cn.edu.scau.cmi.ema.domain.Event9slr;
import cn.edu.scau.cmi.ema.util.CmiSqlUtil;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

@Repository("Event9slrDAO")
@Transactional
public class Event9slrDAOImpl extends AbstractJpaDao<Event9slr> implements Event9slrDAO {

	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(
			Arrays.asList(new Class<?>[] { Event9slr.class }));

	@PersistenceContext()
	private EntityManager entityManager;

	public Event9slrDAOImpl() {
		super();
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}

	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	@Transactional
	public Event9slr findEvent9slrById(Integer id) throws DataAccessException {

		return findEvent9slrById(id, -1, -1);
	}

	@Transactional
	public Event9slr findEvent9slrById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9slrById", startResult, maxRows, id);
			return (Event9slr) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByNumber(String number) throws DataAccessException {

		return findEvent9slrByNumber(number, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByNumber(String number, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByNumber", startResult, maxRows, number);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByNumberContaining(String number) throws DataAccessException {

		return findEvent9slrByNumberContaining(number, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByNumberContaining(String number, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByNumberContaining", startResult, maxRows, number);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByName(String name) throws DataAccessException {

		return findEvent9slrByName(name, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByName(String name, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByName", startResult, maxRows, name);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByNameContaining(String name) throws DataAccessException {

		return findEvent9slrByNameContaining(name, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByNameContaining(String name, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByNameContaining", startResult, maxRows, name);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByFood(String food) throws DataAccessException {

		return findEvent9slrByFood(food, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByFood(String food, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByFood", startResult, maxRows, food);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByFoodContaining(String food) throws DataAccessException {

		return findEvent9slrByFoodContaining(food, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByFoodContaining(String food, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByFoodContaining", startResult, maxRows, food);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByFoodtype(String foodtype) throws DataAccessException {

		return findEvent9slrByFoodtype(foodtype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByFoodtype(String foodtype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByFoodtype", startResult, maxRows, foodtype);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByFoodtypeContaining(String foodtype) throws DataAccessException {

		return findEvent9slrByFoodtypeContaining(foodtype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByFoodtypeContaining(String foodtype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByFoodtypeContaining", startResult, maxRows, foodtype);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoverytime(String discoverytime) throws DataAccessException {

		return findEvent9slrByDiscoverytime(discoverytime, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoverytime(String discoverytime, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDiscoverytime", startResult, maxRows, discoverytime);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoverytimeContaining(String discoverytime) throws DataAccessException {

		return findEvent9slrByDiscoverytimeContaining(discoverytime, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoverytimeContaining(String discoverytime, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDiscoverytimeContaining", startResult, maxRows, discoverytime);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoveryaddress(String discoveryaddress) throws DataAccessException {

		return findEvent9slrByDiscoveryaddress(discoveryaddress, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoveryaddress(String discoveryaddress, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDiscoveryaddress", startResult, maxRows, discoveryaddress);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoveryaddressContaining(String discoveryaddress)
			throws DataAccessException {

		return findEvent9slrByDiscoveryaddressContaining(discoveryaddress, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDiscoveryaddressContaining(String discoveryaddress, int startResult,
			int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDiscoveryaddressContaining", startResult, maxRows,
				discoveryaddress);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrBySubject(String subject) throws DataAccessException {

		return findEvent9slrBySubject(subject, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrBySubject(String subject, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrBySubject", startResult, maxRows, subject);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrBySubjectContaining(String subject) throws DataAccessException {

		return findEvent9slrBySubjectContaining(subject, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrBySubjectContaining(String subject, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrBySubjectContaining", startResult, maxRows, subject);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByProducer(String producer) throws DataAccessException {

		return findEvent9slrByProducer(producer, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByProducer(String producer, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByProducer", startResult, maxRows, producer);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByProducerContaining(String producer) throws DataAccessException {

		return findEvent9slrByProducerContaining(producer, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByProducerContaining(String producer, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByProducerContaining", startResult, maxRows, producer);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrBySource(String source) throws DataAccessException {

		return findEvent9slrBySource(source, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrBySource(String source, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrBySource", startResult, maxRows, source);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrBySourceContaining(String source) throws DataAccessException {

		return findEvent9slrBySourceContaining(source, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrBySourceContaining(String source, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrBySourceContaining", startResult, maxRows, source);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByAdultertype(String adultertype) throws DataAccessException {

		return findEvent9slrByAdultertype(adultertype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByAdultertype(String adultertype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByAdultertype", startResult, maxRows, adultertype);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByAdultertypeContaining(String adultertype) throws DataAccessException {

		return findEvent9slrByAdultertypeContaining(adultertype, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByAdultertypeContaining(String adultertype, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByAdultertypeContaining", startResult, maxRows, adultertype);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByFoodbatchfiller(String foodbatchfiller) throws DataAccessException {

		return findEvent9slrByFoodbatchfiller(foodbatchfiller, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByFoodbatchfiller(String foodbatchfiller, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByFoodbatchfiller", startResult, maxRows, foodbatchfiller);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByFoodbatchfillerContaining(String foodbatchfiller) throws DataAccessException {

		return findEvent9slrByFoodbatchfillerContaining(foodbatchfiller, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByFoodbatchfillerContaining(String foodbatchfiller, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByFoodbatchfillerContaining", startResult, maxRows,
				foodbatchfiller);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByAdulterlink(String adulterlink) throws DataAccessException {

		return findEvent9slrByAdulterlink(adulterlink, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByAdulterlink(String adulterlink, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByAdulterlink", startResult, maxRows, adulterlink);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByAdulterlinkContaining(String adulterlink) throws DataAccessException {

		return findEvent9slrByAdulterlinkContaining(adulterlink, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByAdulterlinkContaining(String adulterlink, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByAdulterlinkContaining", startResult, maxRows, adulterlink);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDetectmethod(String detectmethod) throws DataAccessException {

		return findEvent9slrByDetectmethod(detectmethod, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDetectmethod(String detectmethod, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDetectmethod", startResult, maxRows, detectmethod);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDetectmethodContaining(String detectmethod) throws DataAccessException {

		return findEvent9slrByDetectmethodContaining(detectmethod, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDetectmethodContaining(String detectmethod, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDetectmethodContaining", startResult, maxRows, detectmethod);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByUrl(String url) throws DataAccessException {

		return findEvent9slrByUrl(url, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByUrl(String url, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByUrl", startResult, maxRows, url);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByUrlContaining(String url) throws DataAccessException {

		return findEvent9slrByUrlContaining(url, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByUrlContaining(String url, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByUrlContaining", startResult, maxRows, url);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDescription(String description) throws DataAccessException {

		return findEvent9slrByDescription(description, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDescription(String description, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDescription", startResult, maxRows, description);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByDescriptionContaining(String description) throws DataAccessException {

		return findEvent9slrByDescriptionContaining(description, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByDescriptionContaining(String description, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByDescriptionContaining", startResult, maxRows, description);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByImported(Boolean imported) throws DataAccessException {

		return findEvent9slrByImported(imported, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByImported(Boolean imported, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByImported", startResult, maxRows, imported);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrByIslocked(Boolean islocked) throws DataAccessException {

		return findEvent9slrByIslocked(islocked, -1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByIslocked(Boolean islocked, int startResult, int maxRows)
			throws DataAccessException {
		Query query = createNamedQuery("findEvent9slrByIslocked", startResult, maxRows, islocked);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@Transactional
	public Event9slr findEvent9slrByPrimaryKey(Integer id) throws DataAccessException {
		return findEvent9slrByPrimaryKey(id, -1, -1);
	}

	@Transactional
	public Event9slr findEvent9slrByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9slrByPrimaryKey", startResult, maxRows, id);
			return (Event9slr) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	@Transactional
	public Set<Event9slr> findEvent9slrsByIds(Set<Integer> ids) throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9slrsByIds", -1, -1, ids);
			return new HashSet(query.getResultList());
		} catch (NoResultException nre) {
			return null;
		}
	}

	@Transactional
	public Set<Event9slr> findAllEvent9slrs() throws DataAccessException {

		return findAllEvent9slrs(-1, -1);
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findAllEvent9slrs(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllEvent9slrs", startResult, maxRows);
		return new LinkedHashSet<Event9slr>(query.getResultList());
	}

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Event9slr> findEvent9slrByCompositeProperities(String sql, int startResult, int maxRows) {
		return new LinkedHashSet<Event9slr>(createQuery(sql, startResult, maxRows).getResultList());
	}

	@Transactional
	public Set<Event9slr> findEvent9slrsByDetachedCriteria(CmiPagination page) throws DataAccessException {
		DetachedCriteria detachedCriteria = CmiSqlUtil.createDetachedCriteria(page, Event9slr.class);
		Session session = (Session) entityManager.getDelegate();
		Set<Event9slr> event9slrs = new HashSet(detachedCriteria.getExecutableCriteria(session)
				.setFirstResult(page.getSearchBeginCursor()).setMaxResults(page.getPaginationSize()).list());

		return event9slrs;
	}

	@Transactional
	public Event9slr findEvent9slrByPhysicalPrimaryKey(String number) throws DataAccessException {
		return findEvent9slrByPhysicalPrimaryKey(number, -1, -1);
	}

	@Transactional
	public Event9slr findEvent9slrByPhysicalPrimaryKey(String number, int startResult, int maxRows)
			throws DataAccessException {
		try {
			Query query = createNamedQuery("findEvent9slrByPhyscialPrimaryKey", startResult, maxRows, number);
			return (Event9slr) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	public boolean canBeMerged(Event9slr entity) {
		return true;
	}
}
